package com.lagou.bean;

import com.lagou.service.TestService;
import com.lagou.util.RequestMetrics;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

@Component
public class TestServiceImpl {
    public SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

    @Reference
    private TestService testService;

    public String test() {
        String uuid = UUID.randomUUID().toString();

        RpcContext.getContext().setAttachment("uuid",uuid+"1");
        String t1 = testService.test1();
        RequestMetrics.calculateOnce(uuid+"1");

        RpcContext.getContext().setAttachment("uuid",uuid+"2");
        String t2 = testService.test2();
        RequestMetrics.calculateOnce(uuid+"2");

        RpcContext.getContext().setAttachment("uuid",uuid+"3");
        String t3 = testService.test3();
        RequestMetrics.calculateOnce(uuid+"3");

        return sdf.format(new Date())+t1+"////"+t2+"////"+t3;
    }

}
